// 版权归 瞄你个汪 所有。使用本代码应遵守相关法律法规和Apache 2.0开源许可要求。
package top.geeke.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.EqualsAndHashCode;
// import org.springframework.security.core.GrantedAuthority;
import lombok.NoArgsConstructor;
import top.geeke.entity.base.EntityBase;
import top.geeke.eunm.SysMenuTypeEnum;
import top.geeke.eunm.SysStatusEnum;
import top.geeke.toolkit.supertable.annotation.SuperColumn;
import top.geeke.toolkit.supertable.annotation.SuperIndex;
import top.geeke.toolkit.supertable.annotation.SuperTable;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 系统菜单表
 * </p>
 * @author 瞄你个汪
 * @since 2024-05-01 12:00:00
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "sys_menu")
@SuperTable(value = "系统菜单表", isSystem = true, indexes = {
        @SuperIndex(indexName ="sys_index_{table}_T", indexFields ="title"),
        @SuperIndex(indexName ="sys_index_{table}_T2", indexFields ="type"),
})
public class SysMenu extends EntityBase implements Serializable /*, GrantedAuthority */ {
    private static final long serialVersionUID = 1L;

    @SuperColumn(value = "父ID")
    private Long pId;

    @SuperColumn(value = "菜单类型")
    private SysMenuTypeEnum type;

    @SuperColumn(value = "菜单名称", length = 64)
    private String title;

    @SuperColumn(value = "图标", length = 128, nullable = true)
    private String icon;

    @SuperColumn(value = "路由名称", length = 64, nullable = true)
    private String name;

    @SuperColumn(value = "路由路径", length = 128, nullable = true)
    private String path;

    @SuperColumn(value = "组件路径", length = 128, nullable = true)
    private String component;

    @SuperColumn(value = "重定向", length = 128, nullable = true)
    private String redirect;

    @SuperColumn(value = "权限标识", length = 128, nullable = true)
    private String permission;

    @SuperColumn(value = "是否内嵌")
    private boolean isIframe;

    @SuperColumn(value = "外链链接", nullable = true)
    private String outLink;

    @SuperColumn(value = "是否隐藏")
    private boolean isHide;

    @SuperColumn(value = "是否缓存")
    private boolean isKeepAlive = true;

    @SuperColumn(value = "是否固定")
    private boolean isAffix;

    @SuperColumn(value = "状态")
    private SysStatusEnum status = SysStatusEnum.Enabled;

    @SuperColumn(value = "排序", defaultValue = "100")
    private Integer orderNo = 100;

    @SuperColumn(value = "备注", nullable = true, length = 128)
    private String remark;

    @JsonIgnore
    @JsonIgnoreProperties
    @TableField(exist = false)
    private SysMenu parentMenu;

    @JsonIgnore
    @JsonIgnoreProperties
    @TableField(exist = false)
    private List<SysMenu> children;

    private SysMenu(Long id, Long pId, String title, SysMenuTypeEnum type, int orderNo, Long tenantId) {
        this.setTenantId(tenantId);
        this.setOrderNo(orderNo);
        this.setTitle(title);
        this.setType(type);
        this.setPId(pId);
        this.setId(id);
    }

    /**
     * 创建目录
     * @return 目录类型菜单
     */
    public static SysMenu Dir(Long id, Long pId, String title, String name, String path, String icon, int orderNo, Long tenantId) {
        SysMenu menu = new SysMenu(id, pId, title, SysMenuTypeEnum.Dir, orderNo, tenantId);
        menu.setComponent("Layout");
        menu.setKeepAlive(true);
        menu.setName(name);
        menu.setPath(path);
        menu.setIcon(icon);
        return menu;
    }

    /**
     * 创建菜单
     * @return 菜单项
     */
    public static SysMenu Menu(Long id, Long pId, String title, String name, String path, String component, String redirect, boolean isAffix, String icon, int orderNo, Long tenantId) {
        SysMenu menu = new SysMenu(id, pId, title, SysMenuTypeEnum.Menu, orderNo, tenantId);
        menu.setComponent(component);
        menu.setRedirect(redirect);
        menu.setKeepAlive(true);
        menu.setAffix(isAffix);
        menu.setIcon(icon);
        menu.setName(name);
        menu.setPath(path);
        return menu;
    }

    /**
     * 创建iframe外联
     * @return 菜单项
     */
    public static SysMenu iframeLink(Long id, Long pId, String title, String name, String path, String link, boolean isAffix, String icon, int orderNo, Long tenantId) {
        SysMenu menu = new SysMenu(id, pId, title, SysMenuTypeEnum.Menu, orderNo, tenantId);
        menu.setComponent("layout/routerView/iframe");
        menu.setIframe(true);
        menu.setOutLink(link);
        menu.setAffix(isAffix);
        menu.setIcon(icon);
        menu.setName(name);
        menu.setPath(path);
        return menu;
    }

    /**
     * 创建新窗口外联
     * @return 菜单项
     */
    public static SysMenu outLink(Long id, Long pId, String title, String name, String path, String link, String icon, int orderNo, Long tenantId) {
        SysMenu menu = new SysMenu(id, pId, title, SysMenuTypeEnum.Menu, orderNo, tenantId);
        menu.setComponent("layout/routerView/link");
        menu.setKeepAlive(true);
        menu.setOutLink(link);
        menu.setIcon(icon);
        menu.setName(name);
        menu.setPath(path);
        return menu;
    }

    /**
     * 创建按钮
     * @return 按钮
     */
    public static SysMenu Btn(Long id, Long pId, String title, String permission, int orderNo, Long tenantId) {
        SysMenu menu = new SysMenu(id, pId, title, SysMenuTypeEnum.Btn, orderNo, tenantId);
        menu.setPermission(permission);
        return menu;
    }
}
